﻿<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
            <form id="adminForm" name="adminForm" method="post">
				<div id="toolbar-box">
					<div class="toolbar">
						<ul>
							<li id="toolbar-new"><a href="index.php?option=com_retailshop&view=myshop&task=newevent"><span class="icon-new"></span>New</a></li>
							<li id="toolbar-edit-event"><a href="index.php?option=com_retailshop&view=myshop&task=editevnet"><span class="icon-edit"></span>Edit</a></li>
							<li id="toolbar-delete-event"><a href="#"><span class="icon-delete"></span>Delete</a></li>
						</ul>
					</div>
					<div class="title">
						<h2>Event Manager: Events</h2>
					</div>
            </div>
				<div id="search-box">
					<input id="search" type="text" title="Search title. Prefix with ID: to search for a product ID." placeholder="Search...">
					<button class="btn" type="submit">Search</button>
					<button onclick="document.id('search').value='';this.form.submit();">Clear</button>
				</div>
            <table width="100%">
                <thead>
                  <tr>
                    <th width="5%"><input type="checkbox" title="Check All" value="" name="checkall-toogle"></th>
                    <th width="40%"><a href="#">Title</a></th>
                    <th width="30%"><a href="#">Content</a></th>
                    <th width="15%"><a href="#">Start date</a></th>
                    <th width="15%"><a href="#">End date</a></th>
                  </tr>
                </thead>
                <tbody id="table_event">
				<?php foreach($this->events as $event){ ?>
					<tr>
						<td><input type="checkbox" title="Check" value="<?php echo $event->id; ?>" name="ckbevent[]"></td>
						<td><a href="#"><?php echo substrCustom($event->title,0,100) ; ?></a></td>						
						<td><?php echo substrCustom($event->content,0,200) ; ?></td>						
						<td><?php echo $event->start_date ; ?></td>						
						<td><?php echo $event->end_date ; ?></td>						
					</tr>										
					<?php  } ?>				
                </tbody>
                <tfoot>
                  <tr>
                    <td colspan="5">
                        <?php if(count($this->events) >= 10): ?>
                        <div class="pagination">
							<div class="page">
							Page
							<select size="1" class="inputbox" name="limit" id="limit_event_page">
                              
                            </select>
						  </div>
                          <div class="limit">Display #
                            <select size="1" class="inputbox" name="limit" id="limit_event">
                              <option value="5">5</option>
                              <option value="10">10</option>
                              <option value="15">15</option>
                              <option selected="selected" value="20">20</option>
                              <option value="25">25</option>
                              <option value="30">30</option>
                              <option value="50">50</option>
                              <option value="100">100</option>
                              <option value="0">All</option>
                            </select>
                          </div>
                      	</div>
                        <?php endif; ?>
                      </td>
                  </tr>
                </tfoot>
              </table>
            </form>          		
<script type="text/javascript">
	$(document).ready(function(){
		$("#limit_event").change(function(){			
			var limit =  $(this).val();				
			var page = '';
			for(var i = 1; i < <?php echo count($this->events); ?> /limit + 1; i++){
				page += '<option value="'+ i +'">'+ i +'</option>';
			}
			$('#limit_event_page').html(page);
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limitevent&value="+limit,
				data:{limit:limit},
				type: "POST",
				dataType: "html",
				success:function(data) {									
					$('#table_event').html(data);
				},
				error: function (){
					alert('loi');
				}
			});					
		});	
		$("#limit_event_page").change(function(){			
			var page =  $(this).val();	
			var limit = $('#limit_event').val();				
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limitevent&value="+limit,
				data:{limit:limit,page:page},
				type: "POST",
				dataType: "html",
				success:function(data) {									
					$('#table_event').html(data);
				},
				error: function (){
					alert('loi');
				}
			});					
		});					
	});
</script>			